package com.tangjiali.charStream;

import java.io.FileWriter;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;

public class Solution_topic5 {
    public static void main(String[] args) {
        //2.定义测试类，编写main()方法：定义一个集合
        List<Student> stuList = new ArrayList<>();
        stuList.add(new Student("张三", "男", "20", "88"));
        stuList.add(new Student("李四", "女", "19", "99"));
        System.out.println(stuList);
        //3.遍历这个集合，将每个Student对象中的数据按以下格式写到项目根目录下的student.txt中：
        try ( final FileWriter fw = new FileWriter("student.txt")){
            for (Student student : stuList) {
                fw.write(student.toString()+"\r\n");
            }
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
}

/*1. 请定义一个Student类，属性：姓名、性别、年龄、分数，属性类型都用String。
   无参、全参构造方法
   get/set方法*/
class Student {
    private String name;
    private String gender;
    private String age;
    private String score;

    public Student() {
    }

    public Student(String name, String gender, String age, String score) {
        this.name = name;
        this.gender = gender;
        this.age = age;
        this.score = score;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public String getGender() {
        return gender;
    }

    public void setGender(String gender) {
        this.gender = gender;
    }

    public String getAge() {
        return age;
    }

    public void setAge(String age) {
        this.age = age;
    }

    public String getScore() {
        return score;
    }

    public void setScore(String score) {
        this.score = score;
    }

    @Override
    public String toString() {
        return
                name +
                        ", " + gender +
                        ", " + age +
                        ", " + score
                ;
    }
}